﻿# -*- coding: utf-8 -*-
import time

from odoo import api, fields, models, _
import odoo.addons.decimal_precision as dp
from odoo.exceptions import UserError
import calendar
class FHsaasMK_FHsaasTB(models.TransientModel):
    _name = 'FHsaasMK.FHsaasTB'
    _description = u'FHsaasZW'
    #deposit_account_id = fields.Many2one("account.account", string="Income Account", domain=[('deprecated', '=', False)],
FHSAAS_columns	
    FSubject =fields.Many2one('hr.employee',u'科目',readonly=False,required=False,translate=False)
    FRegistrationdate= fields.Date(u'日期',readonly=False,required=False,translate=False)
    fxsname =  fields.Char(u'学生姓名',readonly=False,required=False,translate=False)				   
    FRegistrationdate1= fields.Date(u'开始日期',readonly=False,required=False,translate=False)
    FRegistrationdate2=  fields.Date(u'结束日期',readonly=False,required=False,translate=False)					   
    Fsetperiod= fields.Many2one('hr.employee',u'时间段',readonly=False,required=False,translate=False)
    FClassroom= fields.Many2one('hr.employee',u'教室',readonly=False,required=False,translate=False) #fields.char(u'上课教室',readonly=False,required=False,translate=False),  
    fhheteacher= fields.Many2one('hr.employee',u'授课老师',readonly=False,required=False,translate=False)  
    FResponsibletea=  fields.Many2one('hr.employee',u'负责老师',readonly=False,required=False,translate=False)
    fnian= fields.Selection([('2011',u'2011'),('2012',u'2012'),('2013',u'2013'),('2014',u'2014'),('2015',u'2015'),('2016',u'2016'),('2017',u'2017'),('2018',u'2018'),('2019',u'2019'),('2020',u'2020')],u'年份',readonly=False,required=False,translate=False)	
    fyuefen= fields.Selection([('01',u'1'),('02',u'2'),('03',u'3'),('04',u'4'),('05',u'5'),('06',u'6'),('07',u'7'),('08',u'8'),('09',u'9'),('10',u'10'),('11',u'11'),('12',u'12')],u'月份',readonly=False,required=False,translate=False)					   
    FGrade=  fields.Many2one('hr.employee',u'年级',readonly=False,required=False,translate=False)
    fkemu=   fields.Char(u'科目',readonly=False,required=False,translate=False)		
	
	

    def action_cancel(self):
        """
        Closes Phonecall to Phonecall form
        """
        return {'type':'ir.actions.act_window_close'}	
    def FClassbb_id_change(self,fnian,fyuefen,context=None):
        vals={}
        #raise osv.except_osv(_('提示2!'), _(FSchedule))
        tinfo_FSchedule=""
        day_begin=None		
        day_end=None		
        if (fyuefen !=False and fnian !=False) :
		
            #prod_line_ids002=self.pool.get('jfcrm.tbschedule').search(cr, uid, [('id','=',FSchedule)], context=context)
            #tinfo_FSchedule=self.pool.get('jfcrm.tbschedule').browse(cr, uid,prod_line_ids002,context=context)[0].FSchedule
            #day_now = '20151022'
            day_now = fnian+fyuefen+'01'			
            #day_begin = day_now[0:4]+'-'+day_now[4:6]+'-'+'01' #月初肯定是1号 所以 直接替换 就可以
            day_begin = day_now[0:4]+'-'+day_now[4:6]+'-'+'01' #月初肯定是1号 所以 直接替换 就可以			
            monthRange = calendar.monthrange(int(day_now[0:3]),int(day_now[4:6]))#得到本月的天数
            day_end = day_now[0:4]+'-'+day_now[4:6]+'-'+str(monthRange[1])			
        vals={'FRegistrationdate1':day_begin	,'FRegistrationdate2':day_end	}
        return {'value': vals}		     
    def ziyuanxd_fdcrm_create(self):
        model_data = self.env['ir.model.data']

        model_self=super(FHsaasMK_FHsaasTB, self).read(['FSubject','fkemu','fxsname','FGrade','fhheteacher','FRegistrationdate','FRegistrationdate1','FRegistrationdate2','Fsetperiod'])[0]
			
		
        domaincontext=[]
		
        '''
		#domaincontext.append(('name_related', 'like', '%'+ model_self_resource_id +'%'))
		
        if(model_self['FSubject']!=False):
			domaincontext.append(('fkemu', 'like', '%'+ model_self['FSubject'][1] +'%'))
			
        if(model_self['fkemu']!=False):
			domaincontext.append(('fkemu', '=', model_self['fkemu']))
        if(model_self['fxsname']!=False):
			domaincontext.append(('fxsname', '=', model_self['fxsname']))
			
        if(model_self['FGrade']!=False):
			domaincontext.append(('fbanji', '=', model_self['FGrade'][1]))
        if(model_self['fhheteacher']!=False):
			domaincontext.append(('fsklaoshi', '=', model_self['fhheteacher'][1]))			
        if(model_self['FRegistrationdate']!=False):
			domaincontext.append(('fdata', '=', model_self['FRegistrationdate']))
			
        if(model_self['FRegistrationdate1']!=False):
			domaincontext.append(('fdata', '>=', model_self['FRegistrationdate1']))
        if(model_self['FRegistrationdate2']!=False):
			domaincontext.append(('fdata', '<=', model_self['FRegistrationdate2']))			
			
        if(model_self['Fsetperiod']!=False):
			domaincontext.append(('fshiduan', '=', model_self['Fsetperiod'][1]))		
        print('---kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk--')
        print(domaincontext)		
        #scontext={"search_default_FAdddateks":model_self.FAdddateks,"search_default_FAdddatejs":model_self.FAdddatejs,}		
		'''	
        value = {
            'name': '查询向导',			
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': '模块.TB替换',
            'res_id': 1,
            'views': [(False, 'tree'),(False, 'form')],
            'type': 'ir.actions.act_window',
            'domain':domaincontext ,					
        }		
		
        return value
		
    def ziyuanxd_fdcrm_0001(self):
        model_data = self.env['ir.model.data']
        model_self=super(fhtest002_tbclue, self).read()[0]
			
		
        domaincontext=[]
				
			
        value = {
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': 'fhtest002.weishui001',
            'res_id': 1,
            'views': [(False, 'tree'),(False, 'form')],
            'type': 'ir.actions.act_window',
            #'domain':domaincontext ,					
        }


    @api.multi
    def ziyuanxd_fdcrm_002(self):
        print('-------------综合监控:-------------')

        action = {
            'name': '66666',		
            'type': 'ir.actions.client',
            'tag': 'web_report.main',
            'context':{'show_mode_selector': False},
            }
        return action	
    @api.multi
    def ziyuanxd_fdcrm_003(self):
        request.session.state=self.state
        print('--------ok-------------')#request.session.state=self.state

        ir_model_data = self.env['ir.model.data']
        compose_form = ir_model_data.get_object_reference('base', 'view_workflow_diagram2')	
        return {
            'view_type': 'form',
            'view_mode': 'diagram',
            'res_model': 'workflow',
            'res_id': 1,
            'views':[(compose_form and compose_form[1] or False, 'diagram')],#[(False, 'diagram')],
            'type': 'ir.actions.act_window',
        }	
        return action 


    @api.multi
    def ziyuanxd_fdcrm_005(self):
        action = {
            'name': 'FEC',
            'type': 'ir.actions.act_url',
            'url': "web?debug=1#menu_id=71&action=78",
            'target': 'self',
            }
        return action 		
FHsaasMK_FHsaasTB()
